<?php



if (! function_exists('getUuid'))
{

    /**
     * 生成32位的uuid随机字符串
     * @param  [type] $length [要生成的字符串的长度]
     * @return [type] [description]
     * @author [name] [Leen]
     * @date(2016-08-19)
     */
    function getUuid($length = 32)
    {

        //---------------------- 生成32位的uuid随机字符串 ----------------------

        mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.

        $charid = strtoupper(md5(uniqid(rand(), true)));

        /*$hyphen = chr(45);// "-"

        $uuid = chr(123)// "{"

                .substr($charid, 0, 8).$hyphen

                .substr($charid, 8, 4).$hyphen

                .substr($charid,12, 4).$hyphen

                .substr($charid,16, 4).$hyphen

                .substr($charid,20,12)

                .chr(125);// "}"*/

        $uuid = substr($charid, 0, $length);

        return $uuid;
    }
}



if (! function_exists('formatArray'))
{

    /**
     * 格式化数组，将数组中的空值去掉，使数组成为连续不为空的数组
     * @param  [type] $length [要生成的字符串的长度]
     * @return [type] [description]
     * @author [name] [Leen]
     * @date(2016-08-27)
     */
    function formatArray(Array $arr)
    {

        $num = 0;

        $arrs = [];

        foreach ($arr as $key => $value) {

            if (empty($value)) {

                continue;
            }

            $arrs[$num] = $value;

            $num++;
        }

        return $arrs;
    }
}

